<?php

namespace app\repository\dao\api;

use support\Db;

class MerchantDao
{
    public function getList(array &$data): array
    {
        $fields = [
            'hq_code',
            'market_orgz_id',
            'id',
            'type',
            'code',
            'name',
            'contact',
            'tel',
            'nature',
            'created_at',
            'identifi_code',
            'is_contract'
        ];
        $query = Db::table('merchant')
            ->when($data['type'], function ($query) use (&$data) {
                return $query->where('type', $data['type']);
            });

        $total = $query->count();
        $list = $query->offset($data['start'])
            ->limit($data['length'])
            ->orderBy('id', 'DESC')
            ->select($fields)
            ->get()->toArray();
        return ['total' => $total, 'list' => $list];
    }
}